package com.example.dell.fastshopping.mall.model;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.example.dell.fastshopping.DuoBao.entity.MenuItem;
import com.example.dell.fastshopping.R;
import com.example.dell.fastshopping.mall.entity.DuoBaoMenu;
import com.example.dell.fastshopping.mall.entity.HeadTab;
import com.example.dell.fastshopping.network.ApiService;
import com.example.dell.fastshopping.network.NetCallback;
import com.example.dell.fastshopping.network.RetrofitClient;
import com.example.dell.fastshopping.network.http.BaseResponse;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class DuoBaoMenuViewModel extends ViewModel {
    private ApiService service = RetrofitClient.getInstance().create(ApiService.class);

    private MutableLiveData<List<DuoBaoMenu>> menulist = new MutableLiveData<>();
    private MutableLiveData<Integer> havePermission = new MutableLiveData<>();
    private MutableLiveData<List<HeadTab>> head = new MutableLiveData<>();

    public ArrayList getBannerList() {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(R.mipmap.banner_defaule);
        list.add(R.mipmap.banner_defaule);
        list.add(R.mipmap.banner_defaule);
        list.add(R.mipmap.banner_defaule);
        return list;
    }

    public LiveData<List<DuoBaoMenu>> getList() {
        RetrofitClient.execute(service.getMenuList(), new NetCallback<BaseResponse<List<DuoBaoMenu>>>() {
            @Override
            public void netCallback(BaseResponse<List<DuoBaoMenu>> response) {
                if (response.getCode() == 200) {
                    menulist.setValue(response.getData());
                }
            }
        });
        return menulist;
    }



    public MutableLiveData<List<HeadTab>> getHeadTable() {
        RetrofitClient.execute(service.getHeadTable(), new NetCallback<BaseResponse<List<HeadTab>>>() {
            @Override
            public void netCallback(BaseResponse<List<HeadTab>> o) {
                if (o.isSuccess()) {
                    head.setValue(o.getData());
                }
            }
        });
        return head;
    }
}
